﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Test;

namespace UnitTest
{
    public class Class1
    {
        [Test]
        public void TestBuildXpathFromRoot()
        {
            AuYellowPage page = new AuYellowPage();
            List<string> classes = new List<string> { "class1" };
            var xPath = page.BuildXPath("div", true, classes);
            Assert.AreEqual("//div[contains(@class,'class1')]", xPath);
            List<string> classes2 = new List<string> { "class1", "class2" };
            var xPath2 = page.BuildXPath("div", true, classes2);
            Assert.AreEqual("//div[contains(@class,'class1') and contains(@class,'class2')]", xPath2);
        }
        [Test]
        public void TestBuildXpathFromCurrentNode()
        {
            AuYellowPage page = new AuYellowPage();
            List<string> classes = new List<string> { "class1" };
            var xPath = page.BuildXPath("div", false, classes);
            Assert.AreEqual("./div[contains(@class,'class1')]", xPath);
            List<string> classes2 = new List<string> { "class1", "class2" };
            var xPath2 = page.BuildXPath("div", false, classes2);
            Assert.AreEqual("./div[contains(@class,'class1') and contains(@class,'class2')]", xPath2);
        }
        [Test]
        public void TestBuildXpathNotSpecifyTag()
        {
            var page = new AuYellowPage();
            List<string> classes = new List<string> { "class1" };
            var xPath = page.BuildXPath("", false, classes);
            Assert.AreEqual("./*[contains(@class,'class1')]", xPath);
            List<string> classes2 = new List<string> { "class1", "class2" };
            var xPath2 = page.BuildXPath("", false, classes2);
            Assert.AreEqual("./*[contains(@class,'class1') and contains(@class,'class2')]", xPath2);
        }
        [Test]
        public void TestBuildXpathIgnoreAttributes()
        {
            AuYellowPage page = new AuYellowPage();
            List<string> classes = new List<string> { "class1" };
            List<string> ignoreClass1 = new List<string> { "class3" };
            var xPath = page.BuildXPath("", false, classes, ignoreClass1);
            Assert.AreEqual("./*[contains(@class,'class1') and not(contains(@class,'class3'))]", xPath);
            List<string> classes2 = new List<string> { "class1", "class2" };
            List<string> ignoreClass2 = new List<string> { "class3", "class4" };
            var xPath2 = page.BuildXPath("", false, classes2, ignoreClass2);
            Assert.AreEqual("./*[contains(@class,'class1') and contains(@class,'class2') and not(contains(@class,'class3')) and not(contains(@class,'class4'))]", xPath2);
        }
        [Test]
        public void TestGetInfo()
        {
            AuYellowPage page = new AuYellowPage();
            var coms = page.Search("Acupuncture", 0);
            Assert.IsTrue(coms.Count >= 40,coms.Count.ToString());
        }
    }
}
